Yarn Cheatsheet

November 28, 2022

Installation

Install via npm:

npm install --global yarn

Check installation:

yarn --version

Project Initialization

Starting a new project:

yarn init

Managing Dependencies

Adding a Dependency

yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]

Adding to Different Categories

Add to devDependencies, peerDependencies, and optionalDependencies respectively:

yarn add [package] --dev
yarn add [package] --peer
yarn add [package] --optional

Upgrading a Dependency

yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]

Removing a Dependency

yarn remove [package]

Installing Dependencies

Install all the dependencies of the project:

yarn install

or simply:

yarn

Running Scripts

Add scripts in package.json:

{
  "scripts": {
    "start": "node index.js"
  }
}

Run the script:

yarn start

Profile picture

Written by Manthan Ankolekar who lives and works in Karnataka, India. You should follow them on Twitter